<template>
  <a-config-provider :theme="{ token: settings }" :locale="zhCN">
    <router-view></router-view>
  </a-config-provider>
</template>
<script lang="ts" setup>
import { useCommon } from './stores/Common';
import { useLogin } from './stores/Login';
import { Grid } from 'ant-design-vue';
import EventBus from './utils/EventBus'
import { reactive, provide, ref, onMounted, nextTick } from 'vue';

import zhCN from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import { useDebounceFn } from '@vueuse/core';

dayjs.locale('zh-cn');

// await nextTick()

const CommonStore = useCommon()
const LoginStore = useLogin()

const arr = ['lg', 'xl', 'xxl']
const useBreakpoint = Grid.useBreakpoint;
const breakpoint = useBreakpoint()
const size = ref('')

onMounted(() => {
  size.value = Object.entries(breakpoint.value).findLast((item: [string, boolean]) => item[1] === true)![0]
  CommonStore.setShowSearch(arr.includes(size.value))
})



const handleResize = useDebounceFn(() => {
  size.value = Object.entries(breakpoint.value).findLast((item: [string, boolean]) => item[1] === true)![0]
}, 1000)

window.onresize = () => {
  handleResize()
}

const settings = reactive({
  // 默认色板
  colorPrimary: '#9d7dff',
  // 警告色
  colorWarning: '#fa541c',
  // 错误色
  colorError: '#f5222d',
  // 背景色
  colorBgContainer: '#fff',
  // 文字色
  colorTextBase: '#000',
  // 圆角
  borderRadius: 4,
  // 边框色
})


EventBus.on('LoginSuccess', (department: string | null, id: number | null, illArea: string | null,) => {
  CommonStore.getData(department, id, illArea)
})


EventBus.on('ResetStore', () => {
  console.log('重置数据');

  CommonStore.$reset()
  LoginStore.$reset()
})

// function getData(department: string | null, id: number | null, illArea: string | null,) {
//   if (LoginStore.isLogin) {
//     CommonStore.setUser(department, id, illArea)
//       .then(res => {
//         CommonStore.getAllDevice()
//       }).then(res => {
//         return Promise.all([CommonStore.getAllFirstData(), CommonStore.getAllSecondData()])
//       }).then(() => {
//         return CommonStore.handleSecondData()
//       }).then((res) => {
//         return CommonStore.handleThirdData()
//       }).then(res => {
//         return CommonStore.getVersion()
//       }).then(res => {
//         if (res) {
//           EventBus.emit('PageChange', 'Home')
//         }
//       })
//   }
// }



</script>